package com.pic4493.controls;

import com.pic4493.adapter.AdpCstLayListView;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

public class CstLayoutListView extends LinearLayout
{

   private AdpCstLayListView adapter;
   private OnClickListener onClickListener = null;

   /**
    * 绑定布局
    */
   public void bindLinearLayout()
   {
	  int count = adapter.getCount();
	  for (int i = 0; i < count; i++)
	  {
		 View v = adapter.getView(i, null, null);

		 v.setOnClickListener(this.onClickListener);
         
		 v.setFocusable(true);
		 v.setClickable(true);
		
		 addView(v, i);
	  }
	  Log.v(" countTAG ", "" + count);
   }

   public CstLayoutListView(Context context)
   {
	  super(context);
   }

   public CstLayoutListView(Context context, AttributeSet attrs)
   {
	  super(context, attrs);
   }

   /**
    * 获取Adapter
    * 
    * @ return adapter
    */
   public AdpCstLayListView getAdpater()
   {
	  return adapter;
   }

   public void cleanData()
   {
	  this.adapter=null;
	  removeAllViews();
   }
   
   /**
    * 设置数据
    * 
    * @ param adpater
    */
   public void setAdapter(AdpCstLayListView adpater)
   {
	  this.adapter = adpater;
	  bindLinearLayout();
   }

   /**
    * 获取点击事件
    * 
    * @ return
    */
   public OnClickListener getOnclickListner()
   {
	  return onClickListener;
   }

   /**
    * 设置点击事件
    * 
    * @ param onClickListener
    */
   public void setOnclickLinstener(OnClickListener onClickListener)
   {
	  this.onClickListener = onClickListener;
   }
}
